home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / srefv112.zip / INSTALL.CMD < prev    next >
OS/2 REXX Batch file  |  1996-05-26  |  22KB  |  763 lines

  1. /* this is the SRE-FILTER installation program */
  2.  
  3. /* Load up advanced REXX functions */
  4. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  5. call SysLoadFuncs
  6.  
  7.  
  8. copyall=0
  9. echo off
  10. /* --- Load the tcp/ip function library, if necessary --- */
  11. if RxFuncQuery("SockLoadFuncs")=1 then  do    /* not there */
  12.   call RxFuncAdd "SockLoadFuncs","rxSock","SockLoadFuncs"
  13.   call SockLoadFuncs
  14. end
  15.  
  16. ansion=checkansi()
  17. if ansion=1 then do
  18.   aesc='1B'x
  19.   cy_ye=aesc||'[37;46;m'
  20.   normal=aesc||'[0;m'
  21.   bold=aesc||'[1;m'
  22.   re_wh=aesc||'[31;47;m'
  23.   reverse=aesc||'[7;m'
  24. end
  25. else do
  26.   cy_ye="" ; normal="" ; bold="" ;re_wh="" ; 
  27.   reverse=""
  28. end  /* Do */
  29.  
  30. cls
  31. say  " " ; say
  32.  
  33. call lineout, bold cy_ye
  34. call lineout, "This is the SRE-FILTER  (v 1.11) installation program (5/96).     "
  35. call lineout, "... an HTTP filter for the GoServe OS/2 Internet Server      "
  36. call lineout, normal
  37. say " This program will ask for the names of a few directories,"
  38. say " and will copy a number of files to these directories."
  39. say "  "
  40.  
  41. if yesno(" Are you ready to continue ")=1 then
  42.  say " Okay ... " 
  43. else do
  44.  say " See you later?.. "
  45.  exit
  46. end
  47.  
  48.  
  49. say " First,what is your IP address (it will be given OWNER privileges)"
  50. ipaddr=" "
  51. sagain:
  52. call charout , bold " What is your IP address:? " normal
  53. pull youraddr
  54. parse var youraddr t1 '.' .
  55. isnum=0
  56. if  datatype(t1)='NUM' then
  57.   isnum=1
  58. say " wait while that address is checked ... "
  59. chk=host(youraddr)
  60. if translate(word(chk,2))<>"IS" then do
  61.     call lineout,re_wh " Unable to find  address: " youraddr normal
  62.     say "    OWNER variable not assigned (but you can assign it later)"
  63.     ipaddr=" "
  64. end  /* Do */
  65. else do
  66.    if isnum then
  67.      ipaddr=word(chk,1)
  68.    else
  69.      ipaddr=word(chk,3)
  70.  
  71.    say " Your IP address: " ipaddr
  72. end
  73.  
  74. skip:
  75. nowdir=directory()
  76. adir=filespec("drive",nowdir)
  77. defname=adir||'\GOSERV'
  78. defname2=adir||'\GOHTTP'
  79.  
  80.  
  81. skip:
  82.  
  83. /* -------- Working directory (must exist ) */
  84. say
  85. call lineout, cy_ye " Please enter a few directory names: " normal
  86.  
  87. say " "
  88.  
  89. call lineout, bold  " What is GOSERVE's "working" directory? " normal
  90. say "    ... the SRE-FILTER program files will be written there. "
  91.  
  92. n1:
  93. godir=get_dir(defname)
  94.  
  95. if godir=" " then godir=defname
  96. if godir="n.a." then signal n1
  97.  
  98. godir=strip(godir,'t','\')
  99. gsname=godir||"\GOSERVE.EXE"
  100.  
  101. call sysfiletree gsname,gname2,'F'
  102. if gname2.0=0 then do
  103.    say " Could not find GOSERVE.EXE in " godir "...."
  104.    if yesno(" Do you want to use it anyways?")=1 then signal useit0
  105.    if godir=defname then defname= "n.a."
  106.    signal n1
  107. end  /* Do */
  108.  
  109. useit0: workdir=godir
  110.  
  111. say " "
  112.  
  113. /* -- Get the DATA subdirectory of the working directory */
  114. say " "
  115. say  " Where should SRE-FILTER's Message, Access, & Counter files be installed?"
  116. say  "    .. it is recommended that it be under your working directory ! "
  117. sdatadir=get_dir(workdir||'\DATA')
  118.  
  119.  
  120. /* -- Get the UpLOAD subdirectory of the working directory */
  121. say " "
  122. say  " Where should SRE-FILTER store Uploaded files?"
  123. upload_dir=get_dir(workdir||'\upload')
  124.  
  125.  
  126. /* -- Get the CGI-BIN directory of the working directory */
  127. say " "
  128. say " Where should CGI-BIN files be stored? "
  129. cgibin_dir=get_dir(workdir||'\cgi_bin')
  130.  
  131.  
  132. /* -- Get the data directory */
  133. say " "
  134. call lineout, bold " What is your data directory?" normal
  135. say  '    .. this is  the location of your "home page" '
  136.  
  137.  
  138. datadir=get_dir(defname2)
  139.  
  140.  
  141. /* -- Get the IMGS subdirectory of the data directory */
  142. say " "
  143.  
  144. say  " Where should SRE-FILTER's GIF files be installed?"
  145. say  "    .. it should be under your data directory ! "
  146.  
  147. gifdir=get_dir(datadir||'\IMGS')
  148.  
  149.  
  150. /* -- The "sample and help files" directory */
  151. say " "
  152.  
  153. say " Where should  the Sample and Help Files be installed?"
  154. say "      .. it MUST be under your data directory ! "
  155.  
  156. helpdir=get_dir(datadir||'\SAMPLES',datadir)
  157.  
  158.  
  159. /* --  The "temporary directory" -- */
  160. say " "
  161.  
  162. say " Where should SRE-FILTER's Temporary Directory be "
  163. say "     ... it's recommended, but not required, that this be under "
  164. say "         your data directory "
  165.  
  166.  
  167. tempdir=get_dir(datadir||'\TEMP')
  168.  
  169.  
  170.  
  171. eek=godir||'\srefiltr.*'
  172. call sysfiletree eek,gname3,'F'
  173. /* -- Done with directory creation -- copy files ... */
  174. say " "
  175. call lineout, re_wh "WARNING:  " normal
  176. call lineout, bold  "  If you are re-installing SRE-FILTER, older files may be overwritten." normal
  177. say "      If you have made extensive changes to parameter files, "
  178. say "      you may want to back them up before completing this installation."
  179.  
  180.  
  181. foo=yesno(" Files will now be copied to these directories. Are you ready? ")
  182. if foo=0 then do
  183.   say " Try again later... "
  184.   exit
  185. end
  186.  
  187. say " "
  188. say " Copying miscellaneous SRE-FILTER program files files to " workdir
  189. foo=check_copy('*.80' ,workdir)
  190.  
  191. say " Copying  user configurable parameter files to " workdir
  192. foo=check_copy('*.IN', workdir,' *** THESE ARE USER CONFIGURED FILES : Are you sure?')
  193.  
  194. foo=check_copy('*.RXX',workdir)
  195. foo=check_copy('*.RXL',workdir)
  196. foo=check_copy('MACROEYE.CMD',workdir)
  197. foo=check_copy('REXXLIB.DLL',workdir)
  198. foo=check_copy('*.CON',workdir)
  199. foo=check_copy('*.SWI',workdir)
  200.  
  201. foo=check_copy('XCOUNT.CMD',cgibin_dir)
  202. foo=check_copy('TEST-CGI.CMD',cgibin_dir)
  203.  
  204. say " Copying access control, tracking, and message boxes to " sdatadir
  205. foo=check_copy('*.CTL',sdatadir,'  These are your access control files: Are you sure?')
  206. foo=check_COPY('*.CNT', sdatadir,' These are your "hit-counter" files: Are you sure?')
  207. foo=check_COPY('*.LOG', sdatadir,' This is your default "message box": Are you sure?')
  208.  
  209.  
  210. say " Copying sample and help files to " helpdir
  211. foo=check_COPY('*.HTM',helpdir)
  212. foo=check_COPY('*.key',helpdir)
  213.  
  214. foo=check_COPY('*.DAT',helpdir)
  215. foo=check_COPY('*.DOC',helpdir)
  216. foo=check_COPY('*.MAP',helpdir)
  217. foo=checK_COPY('SAMPMAP.GIF',helpdir)
  218. foo=check_COPY('TESTTABL.TBL',HELPDIR)
  219. foo=check_COPY('TESTTABL.DEF',HELPDIR)
  220.  
  221. SAY ' Copying GIF file archive to  ' gifdir
  222. foo=check_COPY('GIFS.ZIP',gifdir)
  223. meis=directory()
  224. gifis=directory(gifdir)
  225. 'UNZIP GIFS.ZIP'
  226. meis=directory(meis)
  227.  
  228. /* --- customize index.htm  -- */
  229. say " "
  230. call lineout, cy_ye  " ... customizing files ... " normal
  231. say " "
  232. say ' Copying sample home page to ' datadir
  233. thefh=grab_file("INDEX.HT0")
  234. if thefh=0 then do
  235.    Say " ERROR : Could not find sample home page "
  236.    say "         You may need to unzip SREFILTR.ZIP  again? "
  237.    signal done1
  238. end
  239. parse var helpdir foo (datadir) thesamp
  240. thesamp=strip(translate(thesamp,'/','\'),,'/')
  241. thefh=replacestrg(thefh,'helpdirectory',thesamp,'ALL')
  242. dog=datadir||'\INDEX.HTM'
  243.  
  244. drop foo1
  245. tmp=sysfiletree(dog,foo1,'F')
  246. ok=1
  247. if foo1.0>0 & copyall=0 then
  248.   ok=yesno(" Overwrite "||dog"?")
  249.  
  250. if ok=1 then do
  251.   foo=sysfiledelete(dog)          /* delete any prior version */
  252.   aa=stream(dog,'c','open write')
  253.   if aa<>'READY:' then do
  254.     say " ERROR: could not write " dog
  255.     signal done1
  256.   end
  257.   foo=charout(dog,thefh)
  258.   if foo>0 then do
  259.      say " ERROR: Problem writing " dog
  260.      signal done1
  261.   end
  262.   aa=stream(dog,'c','close')
  263. end
  264.  
  265. /*--- Customize IMAGE MAP DEMO --- */
  266. say ' Customizing IMAGE MAP demo document '
  267. thefh=grab_file("SAMPMAP.HT0")
  268. if thefh=0 then do
  269.    Say " ERROR : Could not find  IMAGE MAP demo document "
  270.    say "         You may need to unzip SREFILTR.ZIP  again? "
  271.    signal done1
  272. end
  273. thefh=replacestrg(thefh,'helpdirectory',thesamp,'ALL')
  274. dog=helpdir||'\SAMPMAP.HTM'
  275.  
  276. drop foo1
  277. tmp=sysfiletree(dog,foo1,'F')
  278. ok=1
  279. if foo1.0>0  & copyall=0 then
  280.   ok=yesno(" Overwrite "||dog"?")
  281. if ok=1 then do
  282.   foo=sysfiledelete(dog)          /* delete any prior version */
  283.   aa=stream(dog,'c','open write')
  284.   if aa<>'READY:' then do
  285.      say " ERROR: could not write " dog
  286.      signal done1
  287.   end
  288.   foo=charout(dog,thefh)
  289.   if foo>0 then do
  290.      say " ERROR: Problem writing " dog
  291.      signal done1
  292.   end
  293.   aa=stream(dog,'c','close')
  294. end
  295.  
  296.  
  297. /*-- Customize FILTINST.HTM --- */
  298. say " Creating SRE-FILTER configurator (FILTINST.HTM) for your system "
  299. thefh=grab_file("FILTINST.HT0")
  300. if thefh=0 then do
  301.    Say " ERROR : Could not find FILTINST configurator program. "
  302.    say "         You may need to unzip SREFILTR.ZIP  again? "
  303.    signal done1
  304. end
  305. thefh=replacestrg(thefh,'helpdirectory',thesamp,'ALL')
  306. dog=datadir||'\FILTINST.HTM'
  307.  
  308. drop foo1
  309. tmp=sysfiletree(dog,foo1,'F')
  310. ok=1
  311. if foo1.0>0  & copyall=0 then
  312.   ok=yesno(" Overwrite "||dog"?")
  313.  
  314. if ok=1 then do
  315.   foo=sysfiledelete(dog)          /* delete any prior version */
  316.   aa=stream(dog,'c','open write')
  317.   if aa<>'READY:' then do
  318.      say " ERROR: could not write " dog
  319.      signal done1
  320.   end
  321.   foo=charout(dog,thefh)
  322.   if foo>0 then do
  323.      say " ERROR: Problem writing " dog
  324.      signal done1
  325.   end
  326.   aa=stream(dog,'c','close')
  327.   say "  "
  328.   'COPY ' dog workdir  ' >  nul '
  329. end
  330.  
  331. /* --- Modifying the FILTER program  ---- */
  332.  
  333. looksdir="servdir='workingdirectory'"
  334.  
  335. say " Modifying SREFILTR.80 (the main filter program) "
  336. thefh=grab_file("SREFILTR.A80")
  337. if thefh=0 then do
  338.    Say " ERROR : Could not find  SREFILTR.A80 parameters file. "
  339.    say "         You may need to unzip SREFILTR.ZIP  again? "
  340.    signal done1
  341. end
  342.  
  343. looksdir2="servdir='"||workdir||"'"
  344. thefh=replacestrg(thefh,looksdir,looksdir2)
  345.  
  346. dog=workdir||'\SREFILTR.80'
  347. drop foo1
  348. tmp=sysfiletree(dog,foo1,'F')
  349. ok=1
  350. if foo1.0>0  & copyall=0 then
  351.   ok=yesno(" Overwrite "||dog"?")
  352. if ok=1 then do
  353.   foo=sysfiledelete(dog)          /* delete any prior version */
  354.  
  355.   aa=stream(dog,'c','open write')
  356.   if aa<>'READY:' then do
  357.      say " ERROR: could not write " dog
  358.      signal done1
  359.   end
  360.   foo=charout(dog,thefh)
  361.   if foo>0 then do
  362.      say " ERROR: Problem writing " dog
  363.      signal done1
  364.   end
  365.   aa=stream(dog,'c','close')
  366. end
  367.  
  368.  
  369. /*-- Modifying the INITFILT.80 file -- */
  370.  
  371. say " "
  372.  
  373. say " Modifying the INITFILT.80 parameters file "
  374. thefh=grab_file("INITFILT.A80")
  375. if thefh=0 then do
  376.    Say " ERROR : Could not find  INITFILT.A80 parameters file. "
  377.    say "         You may need to unzip SREFILTR.ZIP  again? "
  378.    signal done1
  379. end
  380.  
  381. thefh=replacestrg(thefh,'workingdirectory',workdir,'ALL')
  382. thefh=replacestrg(thefh,'workingdir',workdir,'ALL')
  383.  
  384. thefh=replacestrg(thefh,'workingdatadir',sdatadir,'ALL')
  385. thefh=replacestrg(thefh,'temporarydir',tempdir,'ALL')
  386. thefh=replacestrg(thefh,'owneraddress',ipaddr,'ALL')
  387. thefh=replacestrg(thefh,'uploaddir',upload_dir,'ALL')
  388. thefh=replacestrg(thefh,'cgibindirectory',cgibin_dir,'ALL')
  389.  
  390. dog=workdir||'\INITFILT.80'
  391. drop foo1
  392. tmp=sysfiletree(dog,foo1,'F')
  393. ok=1
  394. if foo1.0>0  & copyall=0 then do
  395.   ok=yesno(" Overwrite "||dog"?")
  396.   if ok=1 then do
  397.       say dog " is your server-configuration file... "
  398.       ok=yesno("        are you sure you want to overwrite it?")
  399.   end
  400. end
  401.  
  402. if ok=1 then do
  403.   foo=sysfiledelete(dog)          /* delete any prior version */
  404.  
  405.   aa=stream(dog,'c','open write')
  406.   if aa<>'READY:' then do
  407.      say " ERROR: could not write " dog
  408.      signal done1
  409.   end
  410.   foo=charout(dog,thefh)
  411.   if foo>0 then do
  412.      say " ERROR: Problem writing " dog
  413.      signal done1
  414.   end
  415.   aa=stream(dog,'c','close')
  416. end
  417.  
  418.  
  419. done1: nop
  420. call charout , cy_ye ' (hit any key to continue) ' normal
  421. foo=sysgetkey("noecho")
  422.  
  423.  
  424. say " "
  425. say " -------------------------------- "
  426. say " "
  427. poop:
  428. call lineout, bold cy_ye  " SRE-FILTER has been installed... " normal
  429. say " ... but there a few things you must do."
  430. say " 1) Instruct GoServe that SREFILTR.80 is the working filter "
  431. say "     (use the OPTIONS-FILTER tab in the GoServe status window)"
  432. say " 2) Make sure that GoServe knows your data directory "
  433. say "     (use the OPTIONS-DataDir tab in the GoServe status window) "
  434. say ' 3) To customize SRE-FILTER, you should "run" FILTINST.HTM '
  435. say "    "
  436. say " (actually, you should probably read the documentation first!) "
  437. say "  "
  438. say "    To do this (while still at the server): "
  439. say "       a) Fire up your favorite web browser (say, IBM Web Explorer 1.03)"
  440. say '       b) Get /FILTINST.HTM (in the data-directory of your server)'
  441. say '       c) Select the "change parameter values options" '
  442. say "       d) A big fill-in form, listing the current value of SRE-FILTER's  "
  443. say '          user-configurable parameters, and a short description of what '
  444. say '          they do, will appear '
  445. say '       e) Fill in the form and submit it.  '
  446. say '   '
  447. call charout , cy_ye ' (hit any key to continue) ' normal
  448. foo=sysgetkey("noecho")
  449. say " "
  450. say "     As a security feature, before the configurator is run, FILTINST "
  451. say "   checks that the Server and Client addresses match. "
  452. say "   If they do not, then you will be denied access. "
  453. say "   If you want to live dangerously, you can suppress this security feature"
  454. say '      by commenting out the "CHECKIT=1" line near the top of '
  455. say "       FILTINST.80 (in your " workdir " directory )"
  456. say "   (actually, we recommend deleting FILTINST.HTM from " datadir
  457. say "      .. it's a potential security hole) "
  458. say " "
  459. say ' Note that FILTINST.HTM has links to a few "help" documents:'
  460. say '    i) SUMMARY.HTM -- a summary of SRE-FILTER '
  461. say "   ii) INITFILT.DOC -- a detailed description of the SRE-FILTER's "
  462. say '       parameters, with possible choices described for each. '
  463. say '   iii) SREFILTR.HTM -- the complete documentation '
  464. say ' '
  465. call charout , cy_ye ' (hit any key to continue) ' normal
  466. foo=sysgetkey("noecho")
  467.  
  468. say ' '
  469. say  bold '  A Note on ports: ' normal ' If you can not use port 80, all you need to do is '
  470. say '  change all the *.80 files (to *.new_port_number) -- see the '
  471. say '  documentation for details '
  472. say ' '
  473. say ' Your web site is now ready to be built!  '
  474. say '  (just add documents, images, links, etc...)'
  475. say ' '
  476. say ' Notes: You can use INDEX.HTM '
  477. say '        in your data directory (' datadir ') as a template. '
  478. say '        If you use a  different File name as your "home page",'
  479. say "        be sure to set SRE-FILTER's " bold "DEFAULT " normal " variable to point to it. "
  480. say ' '
  481. say ' Good luck.'
  482. say ' '
  483. call lineout, bold  ' (if you have problems, you can contact DANIELH@ECON.AG.GOV )' normal
  484.  
  485.  
  486. exit
  487.  
  488. /* ----------------------------------------------------------------------- */
  489. /* HOST -- return the result of a HOST command  (a ping )                  */
  490. /* ----------------------------------------------------------------------- */
  491. /* This need not be in the main filter program                             */
  492. /* It returns the GoServe command to send back the result                  */
  493.   host: procedure
  494.     do queued(); pull .; end                   /* flush */
  495.     address cmd '@host' arg(1) '| rxqueue'     /* execute the command */
  496.     parse pull hostresult                      /* get result */
  497.     return hostresult
  498. /*
  499.     crlf='0d0a'x
  500.     return 'STRING host' arg(1)':'crlf crlf''hostresult
  501. */
  502.                                                 
  503. /* -------------------- */
  504. /* get a yes or no , return 1 if yes */
  505. yesno:procedure expose normal reverse bold
  506. parse arg fooa , allopt
  507. ayn='  '||bold||'Y'||normal||'es\'||bold||'N'||normal||'o'
  508. if allopt=1 then
  509.    ayn=ayn||'\'||bold||'A'||normal||'ll'
  510. do forever
  511.  foo1=normal||reverse||fooa||normal||ayn
  512.  call charout,  foo1 normal ':'
  513.  pull anans
  514.  if abbrev(anans,'Y')=1 then return 1
  515.  if abbrev(anans,'N')=1 then return 0
  516.  if allopt=1 & abbrev(anans,'A')=1 then return 2
  517.  
  518. end
  519.  
  520.  
  521. /* ------------------------ */
  522. /* ask for directory name,use defname2 as default */
  523. /* give user opportunity to create it */
  524.  
  525. get_dir:procedure expose normal reverse bold 
  526. /* procedure expose reverse normal bold */
  527. parse arg defname2 , mustsub
  528. defname0=defname2
  529.  
  530. n2:
  531. call charout ,  reverse ' <ENTER>=' defname2  normal ' ?'
  532. pull godir
  533.  
  534. if godir=" " then godir=defname2
  535. if godir="n.a." then signal n2
  536.  
  537.  
  538. if mustsub<>"" then do    /* check 'must be subdirectory' option */
  539.   if abbrev(godir,mustsub)=0 then do
  540.      say " This directory MUST be under the " mustsub " directory! "
  541.      say "  .. please re enter ! "
  542.      signal n2
  543.   end
  544. end
  545.  
  546. godir=strip(godir,'t','\')
  547. gdname=godir||"\*.*"
  548.  
  549.  
  550. isme=directory()
  551.  
  552. isnew=directory(godir)
  553. if isnew="" then do
  554.    say "    Could not find  " godir
  555.    if yesno("        Would you like to create it")=1 then do
  556.         oo=sysmkdir(godir)
  557.         if oo=0  then
  558.            say "      Directory created: " godir
  559.         else do
  560.            say "      Could not create " godir "(error = " oo
  561.            if godir=defname2 then defname2= "n.a."
  562.            signal n2
  563.         end
  564.    end
  565.    else do
  566.         say " please reenter directory name ... "
  567.         if godir=defname2 then defname2= "n.a."
  568.         signal n2
  569.    end
  570. end  /* Do */
  571.  
  572.  
  573. isme=directory(isme)
  574.  
  575.  
  576.  
  577. return godir
  578.  
  579. /* ------------- */
  580. * ----------------------------------------------------------------------- */
  581. /* REPLACESTRG: In string astring, find first occurence substring target and
  582. .   replace it with substring putme
  583. .      if no target, return unchanged astring
  584. .      if no putme, then remove target
  585. .      if type=backward, then find/change LAST occurence
  586. .      if type=all, find/change all occurences
  587. .      if exactmatch=yes, then do not capitalize during search (exact match only */
  588. /* ----------------------------------------------------------------------- */
  589.  
  590. replacestrg: procedure
  591.  
  592. exactmatch=0
  593. backward=0 ; doall=0
  594.  
  595. parse arg astring ,  target   , putme , type , exactmatch
  596.  
  597. type = translate(type)
  598. if type="BACKWARD" then backward="YES"
  599. if type="ALL" then doall="YES"
  600.  
  601. iat=1
  602. joelen=length(target)
  603. joelen2=length(putme)
  604.  
  605. doagain:                /* here if doall=yes */
  606.  if exactmatch="YES" then do
  607.     if   backward="YES" then
  608.         joe= lastpos(target,astring)
  609.     else
  610.         joe= pos(target,astring,iat)
  611.  end
  612.  else do
  613.    if   backward="YES" then
  614.         joe= lastpos(translate(target),translate(astring))
  615.     else
  616.         joe= pos(translate(target),translate(astring),iat)
  617.  end
  618.  if joe=0 then
  619.          return astring
  620.  
  621.  astring=delstr(astring,joe,joelen)
  622.  if putme<>' ' then
  623.     astring=insert(putme,astring,joe-1)
  624.  
  625.  if doall="YES" then do
  626.      iat=joe+joelen2
  627.      signal doagain
  628.  end
  629. /* else, all done */
  630.  return astring
  631.  
  632. /* ----------------------------------------------------------------------- */
  633. /* GRAB_FILE read in a file, but first check to see if openable, and if
  634. .   openable, open and read it.
  635. .    Returns with the file, or with 0 if file not obtainable.
  636. .    Note that file is closed before returning
  637. .   in,
  638. .    usage:   afile_string=grab_file(the_file,seconds_to_try_for)
  639. */
  640. /* ----------------------------------------------------------------------- */
  641.  
  642.  
  643. grab_file: procedure
  644.  
  645. parse arg afile 
  646.  
  647. ause=stream(afile,'c','open read')
  648. if ause<>"READY:" then
  649.   return 0
  650.  
  651. goo=charin(afile,1,chars(afile))
  652. ause=stream(afile,'c','close')
  653.  
  654. /* get rid of ending ctl-z */
  655. if c2d(right(goo,1))=26 then
  656.   goo=left(goo,length(goo)-1)
  657.  
  658. return goo
  659.  
  660.  
  661. /*******************************************/
  662. /* check for existence of file, then ask user to copy or not */
  663. /* note that for X.* type copies, it only checks once 
  664.    (not for each file, but just for any one of them */
  665. /********************************************/
  666. check_copy: procedure expose copyall reverse bold normal
  667. parse arg file1, dest1 , amess
  668.  
  669. dest2=strip(dest1,'t','\')||'\'
  670.  
  671. filename=dest2||file1
  672.  
  673.  
  674. if copyall=1 then signal doit3
  675.  
  676.  
  677. aa=sysfiletree(filename,isit,'F')
  678.  
  679. ok=1
  680. if aa<>0 then do
  681.    say " Warning: error when looking for pre-existing copy of: " filename
  682.    ok=yesno(" Do you want to copy this file (or files) anyways? ")
  683.    if ok=1 & amess<>""  then
  684.       ok=yesno(amess)
  685. end
  686.  
  687. if isit.0>0 then do
  688.   if pos('*',file1)=0 then do
  689.       say " "
  690.       say " A file exists with the name: " filename
  691.       ok=yesno(" Do you want to overwrite this file? ",1)
  692.       if ok=1 & amess<>""  then
  693.            ok=yesno(amess)
  694.   end
  695.   else do
  696.     say " "
  697.       say " There is at least one file that matches: " filename
  698.       say "  (this match may " bold " not " normal " be one of the files that will be copied!) "
  699.       ok=yesno(" Do you want to copy these files? ",1)
  700.       if ok=1 & amess<>""  then
  701.            ok=yesno(amess)
  702.   end  /* Do */
  703.  
  704. end
  705.  
  706. if ok=2 then do
  707.   say " "
  708.   say "SRE-FILTER will overwrite all files (not just these) "
  709.   copyall=yesno(" Are you sure you want to do this?")
  710.   if copyall=0 then
  711.       ok=yesno(" Do you want to overwrite the current file (or files)? ")
  712. end
  713.  
  714. if ok=0  then return 0
  715.  
  716. doit3:          /* jump here if copyall is on */
  717. 'COPY ' file1 dest1 ' > NUL '
  718.  
  719. return 1
  720.  
  721.  
  722.  
  723.   
  724.  /* ------------------------------------------------------------------ */
  725.  /* function: Check if ANSI is activated                               */
  726.  /*                                                                    */
  727.  /* call:     CheckAnsi                                                */
  728.  /*                                                                    */
  729.  /* where:    -                                                        */
  730.  /*                                                                    */
  731.  /* returns:  1 - ANSI support detected                                */
  732.  /*           0 - no ANSI support available                            */
  733.  /*          -1 - error detecting ansi                                 */
  734.  /*                                                                    */
  735.  /* note:     Tested with the German and the US version of OS/2 3.0    */
  736.  /*                                                                    */
  737.  /*                                                                    */
  738.  CheckAnsi: PROCEDURE
  739.    thisRC = -1
  740.  
  741.    trace off
  742.                          /* install a local error handler              */
  743.    SIGNAL ON ERROR Name InitAnsiEnd
  744.  
  745.    "@ANSI 2>NUL | rxqueue 2>NUL"
  746.  
  747.    thisRC = 0
  748.  
  749.    do while queued() <> 0
  750.      queueLine = lineIN( "QUEUE:" )
  751.      if pos( " on.", queueLine ) <> 0 | ,                       /* USA */
  752.         pos( " (ON).", queueLine ) <> 0 then                    /* GER */
  753.        thisRC = 1
  754.    end /* do while queued() <> 0 */
  755.  
  756.  InitAnsiEnd:
  757.  signal off error
  758.  RETURN thisRC
  759.  
  760.    
  761.  
  762.  
  763.